package com.zlf.service.impl;

import com.zlf.dao.AuthMapper;
import com.zlf.entity.Auth;
import com.zlf.entity.AuthExample;
import com.zlf.service.api.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author ：张利锋
 * @date ：Created in 2020/11/20 19:29
 * @description： TOOD
 * @version: 1.0
 */
@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    AuthMapper authMapper;

    @Override
    public List<Auth> getAllAuth() {
        List<Auth> authList = authMapper.selectByExample(new AuthExample());
        return authList;
    }

    @Override
    public List<Integer> getAuthByRoleId(Integer roleId) {
        List<Integer> authList=authMapper.getAuthByRoleId(roleId);
        return authList;
    }

    @Override
    public void updateAuthByRoleId(Map<String, List<Integer>> map) {
        Integer roleId = map.get("roleId").get(0);
        List<Integer> authIdArray = map.get("authIdArray");
        authMapper.removeAuthByRoleId(roleId);
        if (authIdArray!=null&&authIdArray.size()>0){
            authMapper.addAuthByRoleId(roleId,authIdArray);
        }
    }

    @Override
    public List<String> getAuthNameByAdminId(Integer adminId) {
        List<String> AuthNameList=authMapper.getAuthNameByAdminId(adminId);
        return AuthNameList;
    }

}
